<template>
    <form @submit.prevent="submitForm">
      <table border="1" align="center">
        <tr>
          <td colspan="2"><h1>添加新闻</h1></td>
        </tr>
        <tr>
          <td>新闻标题</td>
          <td align="left"><input type="text" v-model="news.title"/></td>
        </tr>
        <tr>
          <td>新闻内容</td>
          <td><textarea cols="50" rows="5" v-model="news.content"></textarea></td>
        </tr>
        <tr>
          <td>新闻作者</td>
          <td  align="left"><input type="text" v-model="news.author"/></td>
        </tr>
        <tr>
          <td>创建时间</td>
          <td  align="left"><input type="date" v-model="news.createDate"/></td>
        </tr>
        <tr>
          <td colspan="2"><button>提交</button></td>
        </tr>
      </table>
    </form>
</template>

<script>
    export default {
        name: "addNews",
      data(){
          return {
            news:{}
          };
      },
      methods:{
          submitForm(){
            this.axios({
              url:"/news",
              method:"POST",
              data:this.news  //{title:"aaaa",content:"bbbbb"}
            }).then(resp=>{
              //跳转
              this.$router.push("/");
            });
          }
      }
    }
</script>

<style scoped>

</style>
